package com.hue.concurrent.day01;

/*
    join方法的使用
 */
public class Demo09 {
    private static int r = 0;

    public static void main(String[] args) {
        method();
    }

    public static void method() {
        Thread thread = new Thread(() -> {
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            r = 10;
        });
        thread.start();

        try {
            //main线程中调用了thread的join方法，main线程会等待thread线程执行完后执行
            thread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("r = " + r);
    }
}
